//package com.easyexcle.demo.easyExcel.style;
//
//import cn.hutool.core.util.StrUtil;
//import com.alibaba.excel.metadata.CellData;
//import com.alibaba.excel.metadata.Head;
//import com.alibaba.excel.metadata.data.WriteCellData;
//import com.alibaba.excel.util.BooleanUtils;
//import com.alibaba.excel.write.handler.CellWriteHandler;
//import com.alibaba.excel.write.handler.context.CellWriteHandlerContext;
//import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
//import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
//import com.alibaba.excel.write.metadata.style.WriteCellStyle;
//import com.alibaba.excel.write.metadata.style.WriteFont;
//
//import org.apache.poi.ss.usermodel.Cell;
//import org.apache.poi.ss.usermodel.FillPatternType;
//import org.apache.poi.ss.usermodel.IndexedColors;
//import org.apache.poi.ss.usermodel.Row;
//
//import java.lang.reflect.Field;
//import java.util.List;
//
///**
// * @Author: lkz
// * @Title: CellStyleHandler
// * @Description: 指定单元格样式
// * @Date: 2023/6/27 9:08
// */
//
//public class CellStyleHandler implements CellWriteHandler {
//    /**
//     *
//     *3.1版本
//     */
////    @Override
////    public void afterCellDispose(CellWriteHandlerContext context) {
////        // 当前事件会在 数据设置到poi的cell里面才会回调
////        // 判断不是头的情况 如果是fill 的情况 这里会==null 所以用not true
////        Integer rowIndex = context.getRowIndex();
////        Cell cell = context.getRow().getCell(0);
////        String cellValue = cell.getStringCellValue();
////        Integer columnIndex = context.getColumnIndex();
////        if (BooleanUtils.isNotTrue(context.getHead())) {
////            if(0!=rowIndex){
////                if(columnIndex==0||columnIndex==3){
////                    // 第一个单元格
////                    // 只要不是头 一定会有数据 当然fill的情况 可能要context.getCellDataList() ,
////                    // 这个需要看模板，因为一个单元格会有多个 WriteCellData
////                    WriteCellData<?> cellData = context.getFirstCellData();
////                    // 这样样式就设置好了 后面有个FillStyleCellWriteHandler
////                    // 默认会将 WriteCellStyle 设置到 cell里面去 所以可以不用管了
////                    String value = cellData.getStringValue();
////
////                    if (StrUtil.isNotEmpty(value)) {
////                        if(value.contains("总费用")){
////                            // 这里需要去cellData 获取样式
////                            // 很重要的一个原因是 WriteCellStyle 和 dataFormatData绑定的 简单的说 比如你加了 DateTimeFormat
////                            // ，已经将writeCellStyle里面的dataFormatData 改了 如果你自己new了一个WriteCellStyle，可能注解的样式就失效了
////                            // 然后 getOrCreateStyle 用于返回一个样式，如果为空，则创建一个后返回
////                            WriteCellStyle writeCellStyle = cellData.getOrCreateStyle();
////                            writeCellStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
////                            // 这里需要指定 FillPatternType 为FillPatternType.SOLID_FOREGROUND
////                            writeCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
////                            // 创建字体实例
////                            WriteFont cellWriteFont = new WriteFont();
////                            cellWriteFont.setColor((short) 10);
////                            writeCellStyle.setWriteFont(cellWriteFont);
////                        }
////                        else if(cellValue.contains("总费用")&& columnIndex==3){
////
////                            WriteCellStyle writeCellStyle = cellData.getOrCreateStyle();
////                            writeCellStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
////                            writeCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
////
////                            // 创建字体实例
////                            WriteFont cellWriteFont = new WriteFont();
////                            cellWriteFont.setColor((short) 10);
////                            writeCellStyle.setWriteFont(cellWriteFont);
////                        }else if(value.contains("总成本")){
////                            WriteCellStyle writeCellStyle = cellData.getOrCreateStyle();
////                            writeCellStyle.setFillForegroundColor(IndexedColors.LIME.getIndex());
////                            writeCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
////
////                            // 创建字体实例
////                            WriteFont cellWriteFont = new WriteFont();
////                            cellWriteFont.setColor((short) 0);
////                            writeCellStyle.setWriteFont(cellWriteFont);
////                        }else if(cellValue.contains("总成本")&& columnIndex==3){
////                            WriteCellStyle writeCellStyle = cellData.getOrCreateStyle();
////                            writeCellStyle.setFillForegroundColor(IndexedColors.LIME.getIndex());
////                            writeCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
////
////                            // 创建字体实例
////                            WriteFont cellWriteFont = new WriteFont();
////                            cellWriteFont.setColor((short)0);
////                            writeCellStyle.setWriteFont(cellWriteFont);
////                        }
////
////                    }
////                }
////            }
////
////        }
////    }
//
////    @Override
////    public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, List<WriteCellData<?>> cellDataList,
////                                 Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
////
////        if (!isHead) {
////            if (0 != cell.getRowIndex()) {
////                int columnIndex = cell.getColumnIndex();
////                if(columnIndex==0 || columnIndex==3){
////                    WriteCellData<?> cellData = cellDataList.get(0);
////                    String value = cellData.getStringValue();
////                    if (StrUtil.isNotEmpty(value)) {
////                        if (value.contains("总费用")) {
////                            if (columnIndex == 0 || columnIndex == 3) {
////                                // 根据单元格获取workbook
////                                Workbook workbook = cell.getSheet().getWorkbook();
////                                // 单元格策略
////                                WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
////                                // 设置背景颜色黄色
////                                contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
////                                contentWriteCellStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
////                                // 创建字体实例
////                                WriteFont cellWriteFont = new WriteFont();
////                                cellWriteFont.setColor((short) 10);
////                                contentWriteCellStyle.setWriteFont(cellWriteFont);
////                                CellStyle cellStyle = workbook.createCellStyle();
////                                StyleUtil.buildCellStyle(workbook, null, contentWriteCellStyle);
////                               // cell.setCellStyle(cellStyle);
////                                cell.getRow().getCell(columnIndex).setCellStyle(cellStyle);
////
////                            }
////
////                        } else if (value.contains("总成本")) {
////
////                        }
////                    }
////                }
////
////
////            }
////        }
////
////    }
//
//
//
//
//    @Override
//    public void beforeCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Head head, Integer columnIndex, Integer relativeRowIndex, Boolean isHead) {
//
//    }
//
//    @Override
//    public void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
//
//    }
//
//    @Override
//    public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, List<CellData> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
//
//    }
//}
